#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>

#include "system.h"

extern char g_resPath[300];

int ufoGetTouchPos(float *x, float *y)
{
    HIPoint point;
    HICoordinateSpace space = 2;
    HIGetMousePosition(space, NULL, &point);
    *x = point.x;
    *y = point.y;
    
    *x /= ufoGetDPI();
    *y /= ufoGetDPI();
    
    return 0;
}

const char* ufoGetResPath()
{
    if (!g_resPath[0]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        NSString *appDirectory =[[NSBundle mainBundle] bundlePath];
        strcpy(g_resPath, [appDirectory UTF8String]);
        strcat(g_resPath, "/Contents/Resources/Res/");
        [pool release];
    }

    return g_resPath;
}

int ufoGetTouchState()
{
    return GetCurrentButtonState();
}

int ufoLog(const char* tag, const char *fmt, ...)
{
	va_list	arglist;
	char buf[2048] = {0};
	char pszfinalbuf[2048] = {0};
	int len = 0;
    
	va_start(arglist, fmt);
    
	len = vsnprintf(buf,sizeof(buf)-1, fmt, arglist);
    
	va_end(arglist);
	if (len >= 2048)
		buf[2047] = '\0';
    
	snprintf(pszfinalbuf, sizeof(buf)-1, "%s: %s\n", tag, buf);
    
	printf("%s\n", pszfinalbuf);
	
	return 1;
}

float ufoGetDPI()
{
    return 1.0f;
}
